#include <REGX52.H>
#include <INTRINS.H>


typedef unsigned char u8;

void Delay(unsigned int xms)		//@11.0592MHz
{
	unsigned char i, j;

	_nop_();
	
	while(xms--)
	{
		i = 2;
		j = 199;
		do
		{
			while (--j);
		} while (--i);
	}

}

//共阴极数码管字形码编码
u8 code Nixie[] = {0x3f,0x06,0x5b,0x4f,0x66, //0 1 2 3 4
					 0x6d,0x7d,0x07,0x7f,0x6f, //5 6 7 8 9
					 0x77,0x7c,0x58,0x5e,0x79, //A b c d E
					 0x71,0x76,0x30,0x0e,0x38, //F H I J L
					 0x54,0x5c,0x73,0x67,0x50, //n o p q r
					 0x6d,0x3e,0x1c,0x6e};     //s U v y 

void main()
{
	unsigned char NixieSel = 0;
	
	
	//ABC=0b101=0x5=选中Y5，连接LED6，从左往右数第3个数码管
	P2_2 = 1;
	P2_3 = 0;
	P2_4 = 1;
	
	//数码管段码
	P0 = 0x3f;
	
	while(1)
	{
		//移动选中不同的数码管，数码管位选
		P2 &= ~(0x7 << 2);
		P2 |= (NixieSel << 2);
		
		P0 = 0x3f;
		Delay(200);
		
		P0 = 0x06;
		Delay(200);
		
		P0 = 0x5b;
		Delay(200);
		
		P0 = 0x4f;
		Delay(200);
		
		
		P0 = 0x66;
		Delay(200);
		
		P0 = 0x6d;
		Delay(200);
		
		NixieSel++;
		if(NixieSel >= 8)
			NixieSel = 0;
	}
}